package com.k.service.impl;

import com.k.service.MyService;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Collection;

/**
 * @program: SpringSecote01
 * @ClassName MyServiceImpl
 * @description:
 * @author: xiaoJie
 * @create: 2024-09-13 09:45
 * @Version 1.0
 */
@Service
public class MyServiceImpl implements MyService {
    @Override
    public boolean PermssionMenu(HttpServletRequest request, Authentication authentication) {

        Object principal = authentication.getPrincipal();//获取用户信息
        if ( principal != null && principal instanceof User){
            User user = (User) principal;
            Collection<GrantedAuthority> authorities =  user.getAuthorities();
            boolean contains = authorities.contains(new SimpleGrantedAuthority("system:user:add"));
            boolean contains1 = authorities.contains(new SimpleGrantedAuthority("system:user:del"));
            return contains1 && contains;
        }

        return false;
    }
}
